/*
    6. Write a program in C to compare two string without using string library functions. 
    Test Data :
    Input the 1st string : This is first string
    Input the 2nd string : This is first string

    Expected Output :

    The length of both strings are equal and
    also both strings are equal.
*/

#include <stdio.h>
#include <stdlib.h>

char* getStr(char *str)
{
    char ch;
    char *p = str;
    while((ch = getchar()) != '\n'){
        *p = ch;
        p++;
    }
    *p = '\0';
    return str;
}

int getStrLen(char *str)
{
    int len = 0;
    char *p = str;
    while(*p != '\0'){
        len++;
        p++;
    }
    len++; // '\0'
    return len;
}

int main(void)
{
    char *str1 = malloc(1024);
    char *str2 = malloc(1024);
    int len1, len2, cnt;
    printf("Input the 1st string : ");
    getStr(str1);  
    printf("Input the 2nd string : ");
    getStr(str2);
    len1 = getStrLen(str1);
    len2 = getStrLen(str2);
    if(len1 == len2){
        printf("The length of both strings are equal and\n");
        while(*str1 != '\0'){
            if(*str1 == *str2){
                cnt++;
            }
            if(*str1 > *str2){
                printf("1st string biger than 2nd string.");
            }
            if(*str1 < *str2){
                printf("2nd string biger than 1st string.");
            }
            str1++;
            str2++;
        }
        if(cnt == len1 - 1){
            printf("also both strings are equal.");
        }
    }else if(len1 > len2){
        printf("The length of 1st string is bigger than 2nd string \n");
    }else{
        printf("The length of 2nd string is bigger than 1st string \n");
    }
    
    return 0;
}